/**
 * 2018年11月27日下午9:18:27
 * @author 谢进财
 */
package com.baihang.project.ds.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baihang.framework.controller.BaseController;
import com.baihang.framework.kit.JsonKit;
import com.baihang.project.ds.service.CustomerThreeService;

/**
 * 顾客 认筹3
 */
@Controller
@RequestMapping("/customerThree")
public class CustomerThreeController extends BaseController {
	@Autowired
	private CustomerThreeService service;
	
	@RequestMapping
	public String index(Model model) {
		model.addAttribute("sales", service.getSaleMan());
		model.addAttribute("renchous", service.getRenChou());
		return "/project/ds/customerThree/index";
	}
	
	@RequestMapping(value ="/getGrid", produces="application/json;charset=UTF-8")
	@ResponseBody
	public String getGrid(int page,int pagesize,String sortname,String sortorder,String where) {
		String grid = service.getGrid(page,pagesize,sortname,sortorder,where);
		//System.out.println(grid);
		return grid;
	}
	@RequestMapping(value ="/deleteCustomerThree", produces="application/json;charset=UTF-8")
	@ResponseBody
	public String deleteCustomerThree(String tel) throws Exception {
		String result ="false" ;
		String msg ="删除失败";
		if(service.deleteCustomerThree(tel)) {
			result ="true";
			msg="删除成功";
		}
		return JsonKit.toDoubleJson(result, msg);
	}
	
	@RequestMapping(value ="/validateTelCustomerThree", produces="application/json;charset=UTF-8")
	@ResponseBody
	public String validateTelCustomerThree(String tel) throws Exception {
		String result ="false" ;
		String msg ="号码已经存在";
		if(service.validateTelCustomerThree(tel)) {
			result ="true";
			msg="不存在";
		}
		return JsonKit.toDoubleJson(result, msg);
	}
	@RequestMapping(value ="/validateIdCardCustomerThree", produces="application/json;charset=UTF-8")
	@ResponseBody
	public String validateIdCardCustomerThree(String card) throws Exception {
		String result =service.validateIdCardCustomerThree(card);		
		return result;
	}
	
	@RequestMapping(value ="/saveCustomerThree", produces="application/json;charset=UTF-8")
	@ResponseBody
	public String saveCustomerThree(String json) {
		String result ="true";
		String msg ="新增成功";
		if(!service.saveCustomerThree(json)) {
			result="false";
			msg="新增失败";
		}		
		return JsonKit.toDoubleJson(result, msg);
	}
}
